<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">  
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semanticui/semantic.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
    <title>我的推荐</title>  
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    img{
        width: 100%;
    }

    body{
        background-color: #F8F8F8!important;
        /*background-color: #EEF0F5;*/
    }

    .container{
        position: relative;
        top: -2rem;
        background-color: #F8F8F8;
        margin-left: auto;
        margin-right: auto;
        width: 84%;
    }

    .position-body{
        background-color: #f8f8f8;
    }
    .position {
        /*padding-bottom: 15px;*/
        /*border-bottom: solid 1px #CCCCCC;*/
        background-color: white;
        margin: 10px 0 3px 0;
        padding: 10px 5px 0 5px;
        border:0px solid;
        border-radius:5px;
        text-align: left;
    }

    .position_name {
        font-size: 15px;
        font-weight: bold;
        /*color: #0d71bb;*/
    }

    .position_person_image {
        font-size: 14px;
        font-weight: bold;
        color: #F47E2D;
        position: absolute;
        right: 0;
        z-index: 2;
        width: 50px;
        height: 50px;
        margin-right: 30px;
    }

    .avatar {
        width: 100%;
        right: 100%;
        display: block;
        border-radius: 100px;
    }

    .position_person_name {
        font-size: 13px;
        font-weight: bold;
        line-height: 32px;
        color: #61687C;
    }
    .domainName{
        color: white;
        background-color: #275eac;
    }

    .position_person_company {
        font-size: 13px;
        line-height: 16px;
        color: #61687C;
    }

    .position_person_experince {
        font-size: 10px;
        line-height: 30px;
        color: #ADADAD;
    }
    .no_more {
        color: #888;
        font-size: 10px;
        line-height: 35px;
        text-align: center;
        display: none;
    }

</style>
<body>
<%--<div>--%>
<%--    <img class="trend_img"  src="${ctx}/resources/images/trend.jpg" height="100">--%>
<%--    --%>
<%--</div>--%>
<div>
    <img src="${ctx}/resources/images/trend.jpg">
</div>
<div class="container">

    <div id="row-data" class="position-body">

    <c:choose>
        <c:when test="${recommends == null or fn:length(recommends)==0 }">
            <span class="no_more">您还没有推荐过任何职位</span>
        </c:when>

        <c:otherwise>
            <c:forEach items="${recommends}" var="rd">
                <c:forEach items="${rd.recommendedPerson}" var="rp">
                    <div class="position" id="cc" data-position-id="${rp.id}">
<%--                        <input type="hidden" id="status" name="status" value="${rp.status}">--%>
<%--                        <input type="hidden" id="empid" name="empid" value="${rp.personid}">--%>
<%--                        <input type="hidden" id="jobid" name="jobid" value="${rp.jobid}">--%>
                        <div class="position_name">职位：${rd.jobname} | ${rd.cityName}</div>
                        <div class="position_company">${rd.companyname}</div>
                        <div class="position_image">

                            <div class="position_person_image">
<%--                                <c:choose>--%>
<%--                                    <c:when test="{rp.avatar != null || rp.avatar == ''}">--%>
<%--                                        <img class="avatar" src="${rp.avatar}">--%>
<%--                                    </c:when>--%>
<%--                                    <c:otherwise>--%>
<%--                                        <img class="avatar" src="${ctx}/resources/images/head.jpg">--%>
<%--                                    </c:otherwise>--%>
<%--                                </c:choose>--%>

                            </div>

                            <div class="position_person_name">${rp.name} </div>
                            <div class="position_person_company"><span class="domainName">${rp.domainName}</span> &nbsp; ${rp.companyname}</div>
                            <div class="position_person_experince">
                                    ${rp.roleName} | ${rp.cityName} | 工作${rp.workage}年
                            </div>
                        </div>
                    </div>
                </c:forEach>
            </c:forEach>
        </c:otherwise>
    </c:choose>
    </div>

</div>

<!-- 测试用，正式发布关闭 
<div id="testid">
点击获取更多数据
</div>
-->
<input type="hidden" name="lastposition" id="lastposition" value="${fn:length(recommends)}"/> 
<input type="hidden" name="hasmoredata" id="hasmoredata" value="yes"/> 

<script src="${ctx}/resources/jweixin-1.0.0.js"></script>

<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semanticui/semantic.js" type="text/javascript"></script>
<script type="text/javascript">
wx.config({
    debug: false, 
    appId: "${config.appid}",  
    timestamp: ${config.currenttimestamp},  
    nonceStr: "${config.nonceStr}", 
    signature: "${config.signatureStr}", 
    jsApiList: ['checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'showOptionMenu']  
});

    var datasource = {
        moredata: function() {
            var getUrl = '${ctx}/wechat/headhunter/recommend/moreRecommend.do';
            var offset  = $('#lastposition').val();
            var hasmore = $('#hasmoredata').val();

            getUrl += "?offset=" + offset;

            // if(hasmore != "yes"){
            //     alert("已经没有更多数据了");
            //     return false;
            // }

            var that = this;

            $.ajax({ 
                    url: getUrl, 
                    type: "GET", 
                    success: function(data, status){ 
                        if(data.errorcode == 0) {
                            that.appenddata(data);
                        } else {
                            var errorUrl = '${ctx}/wechat/headhunter/error.page';
                            location.href = errorUrl;
                        }
                    }, 
                    error: function(){ 
                        alert("服务出错，请稍后尝试"); 
                    } 
            });
        },

        appenddata:function(data) {
            var offset = parseInt($('#lastposition').val());
            var divstring = "";
            var recommends = data.recommends;

            var count = recommends.length;
            offset += parseInt(count);
            $('#lastposition').val(offset);
            if(count <10) {
                $('#hasmoredata').val('no');
            }
            
            for (var i in recommends) {
                var rd = recommends[i];


                var persons = rd.recommendedPerson;
                for(var j in persons) {
                    var rp = persons[j];
                    divstring += " <div class='position'  data-position-id='"+rp.id+"'>";
                    divstring += " <div class='position_name'>职位："+ rd.jobname + "|"+ rd.cityName+"</div>";
                    divstring += " <div class='position_company'>"+ rd.companyname+ "</div>\n" ;
                    divstring += "<div class='position_image'>\n";
                    divstring += "<div class='position_person_image'>"
                    <%--divstring += "<img class='avatar' src='${ctx}/resources/images/head.jpg'>";--%>
                    divstring += "</div>\n";
                    divstring += "<div class='position_person_name'>"+rp.name+ "</div>\n";
                    divstring += "<div class='position_person_company'>"+rp.companyname+"|" +rp.domainName+"</div>\n";
                    divstring += " <div class='position_person_experince'>"+rp.roleName + "|" + rp.cityName + "|工作" +  rp.workage+ "年\n";
                    divstring += "</div>\n";
                    divstring += " </div>\n";
                    divstring += "</div>";

                }
            }
            var newdata = $(divstring);
            $('#row-data').append(newdata);
        }
    };

    $(document).ready(function() { 
    	var l = sessionStorage.getItem('index_list');
   	 
    	if(null !== l && '' !== l){
    	    $("#row-data").html(l);
    	    $(window).scrollTop(sessionStorage.getItem('index_scroll'));
    	    page = sessionStorage.getItem('index_page');
    	    sessionStorage.removeItem('index_list');
    	    sessionStorage.removeItem('index_scroll');
    	}else{
    		datasource.moredata();
    	};
    	
        $(window).scroll(function() { 
            if($(window).scrollTop() == $(document).height() - $(window).height()) {
                datasource.moredata();
            } 
        });
        <%--$('.position').on('click', function() {--%>
        <%--	var offset = parseInt($('#lastposition').val());--%>
        <%--    var positionid = $(this).attr('data-position-id');--%>
        <%--    var getUrl = '${ctx}/wechat/headhunter/recommend/toView.do?jobid='+positionid;--%>
        <%--    sessionStorage.setItem('index_list',$("#row-data").html());--%>
        <%--    sessionStorage.setItem('index_page',offset);--%>
        <%--    sessionStorage.setItem('index_scroll',$(window).scrollTop());--%>
        <%--    window.location.href = getUrl;--%>
        <%--    --%>
        <%--});--%>

        $('#testid').on('click', function(){
            datasource.moredata();
        });

        wx.ready(function() { 

            wx.onMenuShareAppMessage({
                title: 'Headoffer--专业招聘平台----推荐有奖！',  
                desc: '搭起企业和专业猎头的桥梁，为企业招募英才。',  
                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/shareservice.page',  
                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg',  
                type: 'link'
            });

            wx.onMenuShareTimeline({
                title: 'Headoffer--专业招聘平台----推荐有奖！',  
                desc: '搭起企业和专业猎头的桥梁，为企业招募英才。',  
                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/shareservice.page',  
                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg'
            });

            wx.showOptionMenu();
        });
    });

</script>
</body>
</html>